function SpSpinEdit() {
  //this._v = "";
  //this._nantext = "";
  //this._id = "";
  //this.NegativeChart = "-";
  //this.GroupChar = ".";
  //this.GroupCharReg = "\\." 
  //this.SeparatorChar = ",";
  //this.SeparatorCharReg = ",";
  //this.NumberStyle = 0;//0: integer, 1: float
  var _instance = this;
  var _util = Library.WebControl.Util;
  var _textId;
  //var _valueId;
  var _currentText;
  var _numberStyle;
  var _groupCharReq;
  var _groupChar;
  var _notANumberText = "";
  var _negativeChar = "-";
  var _separatorChar;
  var _separatorCharReg;
  this.Init = function(clientName, textId, numberStyle, groupCharReq, groupChar, separatorChar, separatorCharReg) {
    _globalHashObject.Add(clientName, _instance);
    window[clientName] = _instance;
    _textId = textId;
    _numberStyle = numberStyle;
    _groupCharReq = groupCharReq;
    _groupChar = groupChar;
    _separatorCharReg = separatorCharReg;
    _separatorChar = separatorChar;
  };
  this.SetNotANumberText = function(notAnumberText) {
    _notANumberText = notAnumberText;
  };
  function getTextControl() {
    return _util.GetObjectById(_textId);
  };

  function deletePoint(s) {
    s = s + "";
    if (s.length == 0)
      return "";
    var re = new RegExp(_groupCharReq, "g");
    return s.replace(re, "");
  };
  function showAlert() {
    if (_notANumberText.length > 0)
      alert(_notANumberText);
  };


  function getStringNumber(s) {
    var r = getResultNumber(s);
    if (!r[0])
      showAlert();
    return r[1];
  };
  function formatInt(s) {
    var t = getStringNumber(s);
    if (t.length <= 3)
      return t;
    var r = '';
    t = deletePoint(t);
    var j = 1;
    for (var i = t.length - 1; i >= 0; i--) {
      r = t.charAt(i) + r;
      if (j == 3) {
        if (i != 0) {
          r = _groupChar + r;
        }
        j = 0;
      }

      j++;
    }


    return r;
  };
  function formatDouble(str) {
    if (str == "" || str == null) {
      return "";
    }

    var paras = str.split(_separatorChar);

    if (paras.length > 2) {
      showAlert();
    }
    else
      if (paras.length == 1) {
      return formatInt(paras[0]);
    }


    return formatInt(paras[0]) + _separatorChar + getStringNumber(paras[1]);
  };
  function getResultNumber(s) {
    if (s == null || s == "") {
      return [true, ""];
    }
    s = s + "";
    s = s.replace(/ /g, "");
    if (s.length == 0)
      return [true, ""];

    var startWithNegative = s.match("^" + _negativeChar) == null ? false : true;
    var rs = "";
    var str = s;
    if (startWithNegative) {
      rs = _negativeChar;
      str = s.substring(rs.length);
    }

    var ps = str.split(_groupChar);
    for (var j = 0; j < ps.length; j++) {
      var cs = ps[j];
      for (var k = 0; k < cs.length; k++) {
        var c = parseInt(cs.charAt(k));
        if (!(c >= 0 && c <= 9) || isNaN(c)) {
          if (j > 0 && k == 0)
            return [false, rs.substring(0, rs.length - _groupChar.length)];
          return [false, rs];
        }
        else {
          rs += c;
        }
      }
      rs += _groupChar;
    }

    return [true, s];
  };

  this.GetText = function() {
    return getTextControl().value;
  };
  this.Focus = function() {
    getTextControl().focus();
  };
  this.KeyUp = function() {
    var ip = getTextControl();
    if (_currentText == ip.value)
      return;
    if (_numberStyle == 0) {
      ip.value = formatInt(ip.value);
    }
    else
      if (_numberStyle == 1) {
      ip.value = formatDouble(ip.value);
    }
    _currentText = ip.value;
  };

  this.GetValue = function() {
    var t = _instance.GetText();
    t = deletePoint(t);
    t = t.replace(/ /g, "");
    if (t.length == 0)
      return 0;
    if (t == _negativeChar)
      return 0;
    if (_numberStyle == 0) {
      return parseInt(t);
    }
    if (_numberStyle == 1) {
      var re = new RegExp(_separatorCharReg, "g");
      t = t.replace(re, ".");
      return parseFloat(t);
    }
    return Number.NaN;
  };
  this.SetText = function(t) {
    _instance.SetValue(t);
  };
  this.SetValue = function(v) {
    if (v == null)
      getTextControl().value = "";
    else
      if (v == "")
      getTextControl().value = "0";
    else {
      v = v + "";
      if (_numberStyle == 0) {
        getTextControl().value = formatInt(v);
      }
      else
        if (_numberStyle == 1) {
        var re = new RegExp("\\.", "g");
        v = v.replace(re, _separatorCharReg);
        getTextControl().value = formatDouble(v);
      }
    }
  };
  this.GetVisible = function() {
    return getTextControl().parentNode.parentNode.style.display != "none";
  };
  this.SetVisible = function(v) {
    getTextControl().parentNode.parentNode.style.display = v ? "" : "none";
  };
  //this.GetEnable=function(){
  //  getTextControl().getAttribute("readonly") != "readonly";
  //};
  //this.SetEnable=function(e) {
  //  _util.SetEnable(getTextControl(), e);      
  //};
  this.Enable = function() {
    if (arguments.length > 0) {
      _util.SetInputEnable(getTextControl(), arguments[0])
    }
    return getTextControl().getAttribute("readonly") != "readonly"; ;
  };

};